package com.sqxgg.drugstore.commonEntity;


import org.springframework.http.HttpStatus;

/**
 * @author zhilei.wang
 *
 */
public class Result {
    /**
     * 请求成功
     *
     * @return
     */
    public static <T> ResponseMessage<T> success() {
        return new ResponseMessage<T>(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase());
    }

    public static <T> ResponseMessage<T> success(T t) {
        return new ResponseMessage<T>(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), t);
    }

    /**
     * 服务器异常
     *
     * @return
     */
    public static <T> ResponseMessage<T> serverError() {
        return serverError(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
    }
    public static <T> ResponseMessage<T> serverError(String message,T t) {
        return serverError(HttpStatus.INTERNAL_SERVER_ERROR.value(), message,t);
    }

    public static <T> ResponseMessage<T> serverError(String message) {
        return serverError(HttpStatus.INTERNAL_SERVER_ERROR.value(), message);
    }

    public static <T> ResponseMessage<T> serverError(Integer code, String message) {
        return serverError(code, message, null);
    }

    public static <T> ResponseMessage<T> serverError(Integer code, String message, T t) {
        return new ResponseMessage<T>(code, message, t);
    }

    /**
     * 请求异常
     *
     * @return
     */
    public static <T> ResponseMessage<T> requestError() {
        return requestError(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase());
    }
    public static <T> ResponseMessage<T> requestError(String message,T t) {
        return serverError(HttpStatus.BAD_REQUEST.value(),message,t);
    }
    public static <T> ResponseMessage<T> requestError(String message) {
        return requestError(HttpStatus.BAD_REQUEST.value(), message);
    }

    public static <T> ResponseMessage<T> requestError(Integer code, String message) {
        return requestError(code, message, null);
    }

    public static <T> ResponseMessage<T> requestError(Integer code, String message, T t) {
        return new ResponseMessage<T>(code, message, t);
    }

    /**
     * 未授权
     *
     * @param message
     * @return
     */
    public static <T> ResponseMessage<T> unAuthorized(String message) {
        return requestError(HttpStatus.UNAUTHORIZED.value(), message);
    }

}
